home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / c_lang / strpp31.zip / REGEXP.H < prev    next >
C/C++ Source or Header  |  1994-04-18  |  3KB  |  88 lines

  1. /* -------------------------------------------------------------------- */
  2. /* String++ Version 3.10                                       04/13/94 */
  3. /*                                                                      */
  4. /* Enhanced string class for Turbo C++/Borland C++.                     */
  5. /* Copyright 1991-1994 by Carl W. Moreland                              */
  6. /*                                                                      */
  7. /* Derived from code Copyright 1988, Jim Mischel.  All rights reserved. */
  8. /*                                                                      */
  9. /* regexp.h                                                             */
  10. /* -------------------------------------------------------------------- */
  11.  
  12. #ifndef _REGEXP_H
  13. #define _REGEXP_H
  14.  
  15. #include "parsestr.h"
  16.  
  17. extern int RSTART;
  18. extern int RLENGTH;
  19. extern int NF;
  20.  
  21. class RegExp
  22. {
  23. private:
  24.   ParseString reExpression;        // holds the regular expression
  25.   StrPP       rePattern;        // holds the compiled version
  26.   char* reLastChar;            // used in Match... functions
  27.  
  28.   const char* MakePattern(void);    // entry point to compile pattern
  29.   const char* ParseExpression(StrPP&);
  30.   const char* ParseTerm(StrPP&);
  31.   const char* ParseFactor(StrPP&);
  32.   char        ParseEscape(void);
  33.   int         ParseClosure(StrPP&);
  34.   const char* ParseCCL(StrPP&);
  35.   const char* ParseDASH(StrPP&, char);
  36.  
  37.   int         IsFactor(void);
  38.   const char* SkipTerm(char* pattern);
  39.  
  40.   int Match(const char*, const char*);    // entry point to match expression
  41.   int MatchTerm(int, char*, char*);
  42.   int MatchOR(int, char*, char*);
  43.   int Match_0_1(int, char*, char*);
  44.   int MatchClosure(int, char*, char*, char*);
  45.   int MatchCCL(char, char*);
  46.  
  47. public:
  48.   RegExp(void) {}
  49.   RegExp(const StrPP&);
  50.  
  51.   operator const char*()   { return reExpression(); }
  52.   const char* operator()() { return reExpression(); }
  53.   void operator=(const char*);
  54.   void operator=(const StrPP&);
  55.  
  56.   friend const char* SetFS(const StrPP& s);
  57.   friend int match(const StrPP&, RegExp&);
  58.   friend int operator==(const StrPP& s, RegExp& re);
  59.   friend int operator!=(const StrPP& s, RegExp& re);
  60.   friend ostream& operator<<(ostream&, const RegExp&);
  61. };
  62.  
  63. typedef RegExp Regexp;            // allow the use of Regexp
  64. typedef RegExp Regex;            // allow the use of Regex
  65. extern RegExp FS;
  66.  
  67. inline int operator==(const StrPP& s, RegExp& re)
  68. {
  69.   return (re.Match(s, re.rePattern) == -1) ? 0 : 1;
  70. }
  71.  
  72. inline int operator!=(const StrPP& s, RegExp& re)
  73. {
  74.   return (re.Match(s, re.rePattern) == -1) ? 1 : 0;
  75. }
  76.  
  77. inline int match(const StrPP& s, RegExp& re)
  78. {
  79.   return re.Match(s, re.rePattern);
  80. }
  81.  
  82. int sub(const RegExp& from, const StrPP& to, StrPP& str);
  83. int gsub(const RegExp& from, const StrPP& to, StrPP& str, int count=32767);
  84. int split(const StrPP& s, StrPP*& a, const RegExp& fs);
  85. int index(const StrPP& s, const RegExp& t);
  86.  
  87. #endif
  88.